# 一.字符串的CRUD的操作实践
# 1.增加(create)
Str_a = "a"
Str_a += "b"
print(Str_a)


# 2.检索(retrieve)
content = "abcdefg"
print(content.find("z"))  # find找不到元素会返回-1
print(content.index("efg"))  # index找不到元素会返会报错
print(content.endswith("fg"))
print(content.startswith("abc"))
print(content[2:4])  # 3.索引对多个元素进行检索


# 4.更新(update)
print(content.replace("a", "i"))
tmp = content.split("d")
print(content.split("d"))
print("d".join(tmp))


# 5.删除(delete)
Str_c = "你好 啊 "
Str_d = "你好 啊"
print(Str_c == Str_d)
Str_e = Str_c.strip()
print(Str_e == Str_d)


# 二.完成对字符串格式化的实践,按
Str_date = "2020-10-28 23:%s"
Str_date1 = Str_date % "44"
print(Str_date1)

Str_date2 = "{}-{}-28"
Str_date3 = Str_date2.format(2020, 10)
print(Str_date3)

Name = "姓名"
print(f"{Name}-小明")


# 读取当前文件,并写入新文件
f = open("第二周_第二节.py", "w", encoding="utf-8")
tmp = open("第二周_第二节tmp.py", "r", encoding="utf-8")
f.write(tmp.read())
f.close()
tmp.close()
